package com.xuetang9.t9.hotel.mapper;

import com.xuetang9.t9.hotel.beans.CommodityInfo;
import com.xuetang9.t9.hotel.mapper.condition.ICondition;
import com.xuetang9.t9.hotel.mapper.sql.impl.CommodityInfoMapperSql;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author Pang
 */
public interface ICommodityInfoMapper {

    /**
     * 新增商品
     * @param commodityInfo
     * @return
     */
    @Insert("INSERT INTO g_commodityinfo(comm_name,commtype_id,comm_price,comm_staffprice,comm_discount,comm_num) " +
            "VALUES(#{commName},#{commtypeId},#{commPrice},#{commStaffprice},#{commDiscount})")
    int insert(CommodityInfo commodityInfo);

    /**
     * 根据商品编号删除商品
     * @param id
     * @return
     */
    @Delete("DELETE FROM g_commodityinfo WHERE comm_id = #{id}")
    int deleteById(@Param("id") Integer id);

    /**
     * 根据商品类别删除商品
     * @param typeId
     * @return
     */
    @Delete("DELETE FROM g_commodityinfo WHERE commtype_id = #{id}")
    int deleteByTypeId(@Param("id") Integer typeId);

    /**
     * 更新商品
     * @param commodityInfo
     * @return
     */
    @Update("UPDATE g_commodityinfo SET comm_name=#{commName},commtype_id=#{commtypeId},comm_price=#{commPrice},comm_staffprice=#{commStaffprice},comm_discount=#{commDiscount},comm_num=#{commNum} WHERE comm_id=#{commId}")
    int update(CommodityInfo commodityInfo);

    /**
     * 根据商品查询条件查询
     * @param condition
     * @return
     */
    @SelectProvider(value = CommodityInfoMapperSql.class, method = "selectByAll")
    List<CommodityInfo> selectByAll(@Param("key") ICondition condition);

    /**
     * 根据商品查询条件查询总条数
     * @param condition
     * @return
     */
    @SelectProvider(value = CommodityInfoMapperSql.class, method = "selectByCount")
    Long selectByCount(@Param("key") ICondition condition);
}
